package com.bydq.patrolsystem.config;

import com.bydq.patrolsystem.interceptor.AuthorityInterceptor;
import com.bydq.patrolsystem.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.format.datetime.DateFormatter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyWebMvcConfig implements WebMvcConfigurer {
    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addFormatter(new DateFormatter());
    }

    //登录拦截器
    @Autowired
    private LoginInterceptor loginInterceptor;

    //权限拦截器
    @Autowired
    private AuthorityInterceptor authorityInterceptor;

    /**
     * 添加自定义拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")//拦截的访问路径，拦截所有
                .excludePathPatterns("/static/**","/user/login");//排除的请求路径，排除静态资源路径

//        registry.addInterceptor(authorityInterceptor)
//                .addPathPatterns("/**")//拦截访问路径
//                .excludePathPatterns("/static/**","/user/login","/","/index","/agenda");//排除路径

    }

}
